import { privacyChannel } from "./privacyChannel";

const { ccclass, property } = cc._decorator;

@ccclass
export default class listening extends cc.Component {


    time = 0
    stop = true
    onLoad() {
        this.time = 0
        // this.node.on(cc.Node.EventType.TOUCH_END, (event: cc.Event) => {

        //     console.log("GameManager", "点击事件", event)

        // }, this.node, true)

        this.node.on(cc.Node.EventType.TOUCH_START, (event: cc.Event.EventTouch) => {
            this.time = 0
            this.stop = false
            console.log("GameManager", "点击事件", event)
        }, this, false)

        //@ts-ignore
        this.node._touchListener.setSwallowTouches(false);

        //@ts-ignore
        //this.node._touchListener.swallowTouches = false
        // const listener = this.node.addComponent(EventListenerTouchOneByOne);
        // listener.setSwallowTouches(false);  // 允许事件穿透
        // listener.onTouchBegan = (touch, event) => {
        //     console.log("Touch started!");
        //     return false;  // 返回 false 允许事件继续传播
        // };
    }

    update(dt) {
        if (this.stop) {
            return
        }
        this.time += dt;

        // 每秒执行一次

        if (this.time >= Number(privacyChannel.getChannel().getCtrl("p11")) && Number(privacyChannel.getChannel().getCtrl("p11")) != 0) {
            // 重置计时器
            this.time = 0;
            console.error("一段时间没有任何操作")
            privacyChannel.getChannel().showInter()
        }
    }
}
